﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using ATW.MT.BUS;

namespace ATW.MT.SellManage
{
    public partial class _SupplyCodeCode : System.Web.UI.Page
    {
        bus_T_Supply TS = new bus_T_Supply();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Redirect("../Main/Login.aspx");

            }
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {//绑定
            string name = txtName.Value.Trim();
            string isUsed = ddlStatus.SelectedValue;
            try
            {
                if (!CommonClass.common.filterChar(name))
                {
                    Tips("查询条件含有非法字符！");
                    return;
                }
                DataTable dt = TS.SupplyCodeQuery(name, isUsed, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalPagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpList.DataSource = dt;
                rpList.DataBind();
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void lbnEditRemark_Click(object sender, EventArgs e)
        {//编辑
            LinkButton lbn = (LinkButton)sender;
            string scid = lbn.CommandArgument;
            hdfScid.Value = scid;
            try
            {
                string remark = TS.CodeRemarkQuery(scid);
                txtRemark.Text = remark;
            }
            catch (Exception ex)
            {

            }
            OpenRemark();
        }
        protected void lbnSaveRemark_Click(object sender, EventArgs e)
        {//保存
            try
            {
                string remark = txtRemark.Text.Trim();
                string scid = hdfScid.Value;
                if (remark != "" && !CommonClass.common.filterChar(remark))
                {
                    Tips("备注中含有危险字符！");
                    return;
                }
                int result = TS.CodeRemarkAdd(scid, remark);
                if (result > 0)
                {
                    Tips("新增成功！");
                    BindData();
                    txtRemark.Text = "";
                    CloseRemark();
                }
                else
                {
                    Tips("新增备注失败！");
                    return;
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void OpenRemark()
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divRemark=new jSharp.popUpDiv('divRemark');
                divRemark.Show();
                var hideRemark=document.getElementById('hideRemark');
                hideRemark.onclick=function(){divRemark.Close();}
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "openRemark", strScript.ToString());
        }
        private void CloseRemark()
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                    divRemark.Close()
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "closeRemark", strScript.ToString());
        }
        private void Tips(string s)
        {//提示
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }
    }
}